﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WaveSim.Core.Methods.ODE;
using WaveSim.Core.Equations;
using System.Numerics;

namespace WaveSim.Core.Research
{
    public class Dispersion
    {
        private FieldCalculator calc;
        private IMethodODE method;
        private IWaveEquation eq;

        public Dispersion(IWaveEquation equation, IMethodODE method, double x0, double x1, int n)
        {
            eq = equation;
            this.method = method;
            X0 = x0;
            X1 = x1;
            N = n;
            calc = new FieldCalculator(equation, method);
        }

        public double X0 { get; set; }
        public double X1 { get; set; }
        public int N { get; set; }

        public double[,] Get(double f0, double f1, int n)
        {
            double[,] disp = new double[n, 2];

            double h = (f1 - f0) / (n - 1);
            for (int i = 0; i < n; i++)
            {
                eq.Wave.F0 = f0 + i * h;
                var startValues = eq.StartValues(new double[] { 1 });
                var field = calc.Get(startValues, X0, X1, N);
                var r = eq.Rejection(field);
                var t = eq.Transmission(startValues, r, field);
                disp[i, 0] = eq.Wave.F0;
                disp[i, 1] = t[0].Phase;
            }

            return disp;
        }
    }
}
